﻿using HotUpdateMessage;
using System;
using System.Collections.Generic;
using UnityEngine;

namespace HotUpdateDLL
{
    public abstract class BaseComponent 
    {

        #region 缓存 GameObject & Transform

        // 缓存游戏物体
        public readonly GameObject gameObject;



        // 缓存Transform
        private Transform cacheTransform;

        /// <summary>
        /// 缓存Transform
        /// </summary>
        public Transform CacheTransform
        {
            get
            {
                if (cacheTransform == null)
                    cacheTransform = gameObject.transform;
                return cacheTransform;
            }
        }

        #endregion

        #region 提供Unity基础方法
        /// <summary>
        /// 删除游戏物体
        /// </summary>
        /// <param name="gameObject">需要删除的对象</param>
        protected void Destroy(GameObject gameObject)
        {
            GameObject.Destroy(gameObject);
            // 通知工厂 销毁当前实例 
            MessageCenter.Send(MessageType.DestrotGameObject, this, gameObject);

        }

        /// <summary>
        /// 删除游戏物体
        /// </summary>
        /// <param name="gameObject"> 需要删除的对象</param>
        /// <param name="time"> 延迟多少秒 </param>
        protected void Destroy(GameObject gameObject, float time)
        {
            GameObject.Destroy(gameObject, time);
            MessageCenter.Send(MessageType.DestrotGameObject, this, gameObject);
        }

        /// <summary>
        /// 删除游戏物体,并且从内存中移除
        /// </summary>
        /// <param name="gameObject">需要删除的游戏物体 </param>
        protected void DestroyImmediate(GameObject gameObject)
        {
            GameObject.DestroyImmediate(gameObject);
            MessageCenter.Send(MessageType.DestrotGameObject, this, gameObject);
        }


        #endregion



    }
}
